package henkolib.events;

/**
 * Represents a Simple Event with no arguments.
 * It can be used for Signaling.
 * Should be kept private in the class that invokes it.
 * Use the IPublicSimpleEvent interface for publishing the event.
 * @author Henko
 */

class SimpleEvent implements IPublicSimpleEvent
{
	var subscribed : Array<Void->Void>;
	
	public function new() 
	{
		subscribed = new Array<Void->Void>();
	}
	
	public function Subscribe(func:Void->Void) : Void
	{
		if (Reflect.isFunction(func))
		{
			subscribed.push(func);
		}
	}
	
	public function Unsubscribe(func:Void->Void) : Void
	{
		if (Reflect.isFunction(func))
		{
			subscribed.remove(func);
		}
	}
	
	public function Invoke()
	{
		var callargs = new Array<Dynamic>();
		
		for (func in subscribed)
		{
			Reflect.callMethod( { }, func, callargs);
		}
	}
}